#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
const int INF=1e9;
struct node{
    int d;//chu shi wei zhi;
    int vi;//chu su du;
    int a;//jia su du;
}car[maxn];
int monloc[maxn];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    cin>>T;
    //n,car number;m,monitor number;l,length;v,limit;
    while(T--){
        memset(monloc,0,sizeof(monloc));
        memset(car,0,sizeof(car));
        int n,m,l,v;
        int ans=0;
        cin>>n>>m>>l>>v;
        for(int i=1;i<=n;i++){
            cin>>car[i].d>>car[i].vi>>car[i].a;
        }
        for(int i=1;i<=m;i++){
            cin>>monloc[i];
        }
        for(int i=1;i<=n;i++){
           if(car[i].vi>v) ans++;
        }
        cout<<ans<<" "<<(m-1)<<endl;
    }
    return 0;
}
//rp++;
